import type {CFormGroupProps} from "@/components/CProForm/CFormItem/type";
import {genFieldTypeList} from "@/services/gen/api";

import color from "@/utils/color";

// @ts-ignore
const fields: CFormGroupProps<any>[] = ({enum_}: { enum_: any }): CFormGroupProps<any>[] => {
  // @ts-ignore
  return [
    {
      itemList: [
        {
          name: "label",
          label: "名称",
          labelAlign: "right",
          rules: [
            {
              message: "名称是必填项",
              required: true
            }
          ],
          width: "md",
          placeholder: "名称名称",
        },
        {
          name: "value",
          label: "值",
          labelAlign: "right",
          rules: [
            {
              message: "值是必填项",
              required: true
            }
          ],
          width: "md",
          placeholder: "值名称",
        },
        {
          name: "color",
          label: "颜色",
          labelAlign: "right",
          hidden: !(enum_ as boolean),
          type: "select",
          width: 200,
          rules: [
            {
              message: "值是必填项",

              // @ts-ignore
              required: enum_ as number
            }
          ],
          options: color,
        },
        {
          name: "type",
          label: "字段类型",
          labelAlign: "right",
          rules: [
            {
              message: "值类型是必填项",
              required: !(enum_ as boolean)
            }
          ],
          width: "md",
          type: "select",
          hidden: enum_,
          request: async () => {
            return await genFieldTypeList("").then(res => {
              return res.data.map(item => {
                return {
                  label: item.name,
                  value: item.name
                }
              })
            })
          }
        },

      ]
    }, {
      itemList: [
        {
          name: "desc",
          label: "描述",
          labelAlign: "right",
          width: "md",
          type: "text",
          placeholder: "请输入描述",

        },
      ]
    }
  ]
}
export default fields;
